package com.owg.jigsaw;

import java.io.IOException;
import java.io.InputStream;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;

public class WTrashCan extends WPane
{
	public WTrashCan(WRoot root, Pane ui)
	{
		super(root, true, ui);
		if(ui != null)
			populateUI(ui);
	}
	
	public WTrashCan(WRoot root)
	{
		this(root, null);
	}
	
	@Override
	protected Pane makeUI()
	{
		Pane p = new Pane();
		populateUI(p);
		return p;
	}
	protected void populateUI(Pane p)
	{
		try
		{
			InputStream stream = getClass().getResourceAsStream("GARBAGE.gif");
			if(stream == null)
				throw new IOException("Trash can image does not exist.");
			Image im = new Image(stream);
			
			ImageView imV = new ImageView(im);
			imV.fitWidthProperty().set(240);
			imV.fitHeightProperty().set(240*im.getHeight()/im.getWidth());
			p.getChildren().add(imV);	
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	@Override
	public BlockDropAction accepts(WBlock b)
	{
		return BlockDropAction.TRASH;
	}
}
